home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 7288 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.7 KB

  1. Path: nntp.hut.fi!usenet
  2. From: oahvenla@hyppynaru.cs.hut.fi (Osma Ahvenlampi)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: GetSysTime() accuracy
  5. Date: 14 Apr 1996 02:26:02 +0300
  6. Organization: What, me, organised?
  7. Sender: oahvenla@hyppynaru.cs.hut.fi
  8. Distribution: inet
  9. Message-ID: <jdj91fzso39.fsf@hyppynaru.cs.hut.fi>
  10. References: <4khkab$7p2@toad.stack.urc.tue.nl>
  11. NNTP-Posting-Host: hyppynaru.cs.hut.fi
  12. Mime-Version: 1.0
  13. Content-Type: text/plain; charset=US-ASCII
  14. In-reply-to: jaco@stack.urc.tue.nl's message of 11 Apr 1996 02:38:35 +0200
  15. X-Newsreader: Gnus v5.1
  16.  
  17. In article <4khkab$7p2@toad.stack.urc.tue.nl> jaco@stack.urc.tue.nl (Jaco Schoonen) writes:
  18. >I was playing with GetSysTime() from the timer.device today and I was
  19. >wondering about something:
  20. >If I call it in a loop, the first value for tv.micros will always end with
  21. >0000 or 0001. Then it get's 50-250 times increases by 1 and then suddenly
  22. >skips about 0.02 seconds! 
  23.  
  24. The precision of GetSysTime() is 1 microsecond, although the accuracy
  25. may be off by several orders of magnitude, depending on how well
  26. adjusted the CIA timers and the clock frequency of the machine really
  27. are.
  28.  
  29. You forgot to take into account that if you make a loop such as:
  30.  
  31. for (i = 0 ; i < 1000 ; i++)
  32. {
  33.   GetSysTime(&tv);
  34.   Printf("%ld.%06.6ld\n", tv.tv_secs, tv.tv_micro);
  35. }
  36.  
  37. the calls to GetSysTime() will actually be synchronised to the CIA
  38. clock itself because of the task switches you cause by doing an I/O
  39. operation. That's why the results are milliseconds apart, and pretty
  40. well tied to even thousands.
  41.  
  42. If you make a tight loop that only calls GetSysTime() several times in
  43. a row, you will see that the results only differ by some odd
  44. microseconds. As it happens, on an A3000 the difference will average
  45. to 1 microsecond, but this is directly proportionate to the CPU speed,
  46. of course.
  47.  
  48. However, when I tried a loop that called GetSysTime() and SubTime()
  49. 20000 times within Forbid(), I still got 20 millisecond delays after
  50. each 500 or so calls. I can't explain this immediately, but do note
  51. that 20 milliseconds is 1/50th of a second, ie. one CIA generated
  52. low-resolution "tick" (as defined by DOS). Maybe GetSysTime() forces a
  53. task switch sometimes? I don't know.. Anyway, the normal Exec maximum
  54. task quantum is 4 ticks, or 80 milliseconds, if this has something to
  55. do with the issue.
  56.  
  57. I don't think you will gain any significant increase of accuracy by
  58. using the CIA directly. GetSysTime() is about as low-level a call as I
  59. can imagine.
  60.  
  61. -- 
  62. Preposterous, adj. The idea that murder is a crime.
  63. | "Osma Ahvenlampi" <mailto:oa@iki.fi> <http://www.iki.fi/oa/> |
  64. | Amiga&BeBox&ClassAct&Voodoo&ARTech cool stuff: I-Net225&AWeb |
  65.                                                               --
  66.